/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.区域和检索数组不可变;

import java.util.HashSet;
import java.util.Set;

public class NumArray {
    int[] data;
    int i = 1;

    public NumArray(int[] nums) {
        for (; i < nums.length - 1; ) {
            nums[i] += nums[i++];
        }
        data = nums;
    }

    public int sumRange(int i, int j) {
        if (i == 0)
            return data[j];
        return data[j] - data[i - 1];
    }

}
